/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RestInfoPanel.java
 *
 * Created on Feb 17, 2012, 6:25:38 PM
 */
package handax.GUI;

import handax.controller.DBManager;
import handax.entities.Area;
import handax.entities.Price;
import handax.entities.Rating;
import handax.entities.Restaurant;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import handax.utilities.*;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


/**
 *
 * @author Alexandros
 */
public class RestInfoPanel extends javax.swing.JFrame {
    private int restId;
    /** Creates new form RestInfoPanel */
    public RestInfoPanel(int restId) {
       this.restId = restId;
      DBManager dBM = new DBManager();

        initComponents();
         Restaurant res=dBM.retrieveRestaurantForView(restId);
       
         Area arr= dBM.retrieveArea(res.getArea());
         handax.entities.Category cat= dBM.retrieveCategory(res.getCategory());
         Price pri=dBM.retrievePrices(res.getPrice());
        
         // τραβάει τα στοιχεία του εστιατοριίου απο τη βάση
        this.restaurant.setText("Προβολή Εστιατορίου:  "+res.getRestName());
        this.address.setText("Διεύθυνση:  "+res.getAddress());
        this.phone.setText("Τηλέφωνο:  "+res.getPhone());
        this.prices.setText("Τιμές:  "+pri.getDescr());
        this.info.setText("Πληροφορίες:  "+res.getInfo());
        this.category.setText("Κατηγορία:  "+cat.getDescr());
        this.moreForRest.setText(res.getDescr());
        
        
        Rating ra=dBM.retrieveAvgRating(restId);
       
        // Τραβάει το rating από τη βάση
        this.qualityStarRater1.setRating(ra.getQuality());
        this.priceStarRater2.setRating(ra.getPrice());
        this.timeStarRater3.setRating(ra.getServiceTime());
        this.totalStarRater4.setRating(ra.getAverageRating());
       
        // δίνει το mapkit την περιοχή του εστιατορίου
        //έλεγχος αν λαμβάνεται σωστά η γεωγραφική θέση
        if(Utils.getGeoposition(arr.getDescr())!=null){
        //προβολή της γεωγραφικής θέσης στον χάρτη 
        this.jXMapKit1.setAddressLocation(Utils.getGeoposition(arr.getDescr()));
        }
        else{
            //Προβολή ενημερωτικού μηνύματος
            JOptionPane.showMessageDialog(new JFrame(), "Υπάρχει πρόβλημα με την ανάκτηση της γεωγραφικής θέσης");
        }
        
            //δημιουργία εικόνας "τραβώντας" το path από την βάση
            Image img=Toolkit.getDefaultToolkit().getImage(res.getPhoto());
            
            //δημιουργία εικονιδίου από την εικόνα
            ImageIcon i=new ImageIcon(img);
            
            //δημιουργία ImageObserver
            ImageObserver io = null;
            
            //δημιουργία καινούριου εικονιδίου 
            //με προσαρμοσμένη διάσταση
            Icon ic=Utils.scale(img, 300.0, io);
            
            //τοποθέτηση εικονιδίου στο label
            this.restPhoto.setIcon(ic);

    }
    
    public void setRestId(Integer id) {
        this.restId = id;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXMapKit1 = new org.jdesktop.swingx.JXMapKit();
        info = new javax.swing.JLabel();
        address = new javax.swing.JLabel();
        restaurant = new javax.swing.JLabel();
        prices = new javax.swing.JLabel();
        phone = new javax.swing.JLabel();
        category = new javax.swing.JLabel();
        moreLabel = new javax.swing.JLabel();
        qualityStarRater1 = new handax.utilities.StarRater();
        priceStarRater2 = new handax.utilities.StarRater();
        quality = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        timeStarRater3 = new handax.utilities.StarRater();
        totalStarRater4 = new handax.utilities.StarRater();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        restPhoto = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        moreForRest = new javax.swing.JTextArea();
        close = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(handax.HandaxApp.class).getContext().getResourceMap(RestInfoPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setLocationByPlatform(true);
        setName("Form"); // NOI18N
        setResizable(false);

        jXMapKit1.setDefaultProvider(org.jdesktop.swingx.JXMapKit.DefaultProviders.OpenStreetMaps);
        jXMapKit1.setAddressLocation(new GeoPosition(35.3387, 25.1407));
        jXMapKit1.setName("jXMapKit1"); // NOI18N
        jXMapKit1.setZoom(3);

        info.setFont(resourceMap.getFont("info.font")); // NOI18N
        info.setText(resourceMap.getString("info.text")); // NOI18N
        info.setName("info"); // NOI18N

        address.setFont(resourceMap.getFont("info.font")); // NOI18N
        address.setText(resourceMap.getString("address.text")); // NOI18N
        address.setName("address"); // NOI18N

        restaurant.setFont(resourceMap.getFont("restaurant.font")); // NOI18N
        restaurant.setText(resourceMap.getString("restaurant.text")); // NOI18N
        restaurant.setName("restaurant"); // NOI18N

        prices.setFont(resourceMap.getFont("info.font")); // NOI18N
        prices.setText(resourceMap.getString("prices.text")); // NOI18N
        prices.setName("prices"); // NOI18N

        phone.setFont(resourceMap.getFont("info.font")); // NOI18N
        phone.setText(resourceMap.getString("phone.text")); // NOI18N
        phone.setName("phone"); // NOI18N

        category.setFont(resourceMap.getFont("info.font")); // NOI18N
        category.setText(resourceMap.getString("category.text")); // NOI18N
        category.setName("category"); // NOI18N

        moreLabel.setFont(resourceMap.getFont("moreLabel.font")); // NOI18N
        moreLabel.setText(resourceMap.getString("moreLabel.text")); // NOI18N
        moreLabel.setName("moreLabel"); // NOI18N

        qualityStarRater1.setEnabled(false);
        qualityStarRater1.setName("qualityStarRater1"); // NOI18N
        qualityStarRater1.setRating(4.0F);
        qualityStarRater1.setStars(10);

        javax.swing.GroupLayout qualityStarRater1Layout = new javax.swing.GroupLayout(qualityStarRater1);
        qualityStarRater1.setLayout(qualityStarRater1Layout);
        qualityStarRater1Layout.setHorizontalGroup(
            qualityStarRater1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        qualityStarRater1Layout.setVerticalGroup(
            qualityStarRater1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        priceStarRater2.setEnabled(false);
        priceStarRater2.setName("priceStarRater2"); // NOI18N
        priceStarRater2.setRating(3.0F);
        priceStarRater2.setStars(10);

        javax.swing.GroupLayout priceStarRater2Layout = new javax.swing.GroupLayout(priceStarRater2);
        priceStarRater2.setLayout(priceStarRater2Layout);
        priceStarRater2Layout.setHorizontalGroup(
            priceStarRater2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        priceStarRater2Layout.setVerticalGroup(
            priceStarRater2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        quality.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        quality.setText(resourceMap.getString("quality.text")); // NOI18N
        quality.setName("quality"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        timeStarRater3.setEnabled(false);
        timeStarRater3.setName("timeStarRater3"); // NOI18N
        timeStarRater3.setRating(3.0F);
        timeStarRater3.setStars(10);

        javax.swing.GroupLayout timeStarRater3Layout = new javax.swing.GroupLayout(timeStarRater3);
        timeStarRater3.setLayout(timeStarRater3Layout);
        timeStarRater3Layout.setHorizontalGroup(
            timeStarRater3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        timeStarRater3Layout.setVerticalGroup(
            timeStarRater3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        totalStarRater4.setEnabled(false);
        totalStarRater4.setName("totalStarRater4"); // NOI18N
        totalStarRater4.setRating(3.0F);
        totalStarRater4.setStars(10);

        javax.swing.GroupLayout totalStarRater4Layout = new javax.swing.GroupLayout(totalStarRater4);
        totalStarRater4.setLayout(totalStarRater4Layout);
        totalStarRater4Layout.setHorizontalGroup(
            totalStarRater4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        totalStarRater4Layout.setVerticalGroup(
            totalStarRater4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jLabel10.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setToolTipText(resourceMap.getString("jLabel10.toolTipText")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setToolTipText(resourceMap.getString("jLabel11.toolTipText")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        restPhoto.setIcon(resourceMap.getIcon("restPhoto.icon")); // NOI18N
        restPhoto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        restPhoto.setName("restPhoto"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        moreForRest.setColumns(20);
        moreForRest.setEditable(false);
        moreForRest.setFont(resourceMap.getFont("moreForRest.font")); // NOI18N
        moreForRest.setLineWrap(true);
        moreForRest.setRows(5);
        moreForRest.setText(resourceMap.getString("moreForRest.text")); // NOI18N
        moreForRest.setDisabledTextColor(resourceMap.getColor("moreForRest.disabledTextColor")); // NOI18N
        moreForRest.setName("moreForRest"); // NOI18N
        jScrollPane1.setViewportView(moreForRest);

        close.setText(resourceMap.getString("close.text")); // NOI18N
        close.setToolTipText(resourceMap.getString("close.toolTipText")); // NOI18N
        close.setName("close"); // NOI18N
        close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(quality)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(qualityStarRater1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(priceStarRater2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(timeStarRater3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(totalStarRater4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(category, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(address, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(phone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(info, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(prices, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(restPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, 351, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1)
                            .addComponent(jXMapKit1, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(close)
                        .addGap(157, 157, 157))))
            .addGroup(layout.createSequentialGroup()
                .addComponent(restaurant, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 226, Short.MAX_VALUE)
                .addComponent(moreLabel)
                .addGap(26, 26, 26))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(restaurant)
                    .addComponent(moreLabel))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(address)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(phone)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(prices)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(info))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(category)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(restPhoto, 0, 0, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(qualityStarRater1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(priceStarRater2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(quality)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel9)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(timeStarRater3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(totalStarRater4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jXMapKit1, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(close)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeActionPerformed
       dispose();
    }//GEN-LAST:event_closeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RestInfoPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RestInfoPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RestInfoPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RestInfoPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
              //  new RestInfoPanel(restId).setVisible(true);
            }
        });
    }

   

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel address;
    private javax.swing.JLabel category;
    private javax.swing.JButton close;
    private javax.swing.JLabel info;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXMapKit jXMapKit1;
    private javax.swing.JTextArea moreForRest;
    private javax.swing.JLabel moreLabel;
    private javax.swing.JLabel phone;
    private handax.utilities.StarRater priceStarRater2;
    private javax.swing.JLabel prices;
    private javax.swing.JLabel quality;
    private handax.utilities.StarRater qualityStarRater1;
    private javax.swing.JLabel restPhoto;
    private javax.swing.JLabel restaurant;
    private handax.utilities.StarRater timeStarRater3;
    private handax.utilities.StarRater totalStarRater4;
    // End of variables declaration//GEN-END:variables
}
